CDT = {
	taskCellTemp: null,
	currPageNo: 1,
	pageSize: 20,
	status: 'WAIT_REFUND'
};

//加载任务
function loadTask(pageNo) {
	Tr.get('/seller/task/listWaitCheckShareTask', {
		'vo.taskId': $('#txtTaskId').val(),
		'vo.pageNo': pageNo,
		'vo.pageSize': CDT.pageSize,
	}, function(data) {
		if (data.code != 200) return;
		if (data.results.length <= 0) {
			$('.taskWrapper').addClass('warnBox').html('<span class="iconfont">&#xf00b6;</span>没有任务!');
			return;
		}

		var output = Mustache.render(CDT.taskCellTemp, $.extend(data, {
			modifyTimeStr: function() {
				if(!this.modifyTime){
					return '---';
				}
				return new Date(this.modifyTime).Format('yyyy-MM-dd hh:mm');
			}
		}));
		$('#taskContainer').removeClass('warnBox').html(output);
		$('.pagination').pagination(data.totalCount, {
			items_per_page: CDT.pageSize,
			num_display_entries: 5,
			current_page: pageNo,
			num_edge_entries: 2,
			callback: loadTaskCallBack,
			callback_run: false
		});
		CDT.currPageNo = pageNo;
	});
}

function loadTaskCallBack(index, jq) {
	loadTask(index + 1);
}

function initBase() {
	$('#queryTask').click(function() {
		loadTask(1);
	});

	//选择订单类型
	$(document).on('click', '.taskTab', function() {
		var $me = $(this);
		$me.addClass('focus').siblings().removeClass('focus');
		CDT.status = $me.attr('status');
		loadTask(1);
	});
}

$(function() {

	CDT.taskCellTemp = $('#taskCellTemp').remove().val();
	Mustache.parse(CDT.taskCellTemp);

	initBase();
	loadTask(1);
});

function confirmTask(taskId, id, rejected){
	var r = confirm('确认要进行此操作吗？');
	if(r){
		var p = {};
		p.taskId = taskId;
		p.id = id;
		p.rejected = rejected;
		Tr.post('/task/shareTask/checkTask', p, function(data){
			if(data.code==200){
				alert('确认成功');
				loadTask(1);
			}
		});
	}
}